package com.itheima.Oop01;

public class Student {
    String name;
    int ID;

    private int age;

    public void study(){
        System.out.println("学习");
    }
    public void setAge(int age){
        if(age >= 0 && age <= 120){
            this.age = age;//成员变量和局部变量重名,就近原则,可以this对象指向成员变量
        }else System.out.println("输入有误");
    }
    public int getAge(){
        return this.age;
    }

    public Student(){}
    public Student(int age){//重载+构造方法
        this.age = age;//创建对象时就初始化赋值
        System.out.println("调用Student构造方法!");
    }


}
